import {
  BasicColumn
} from '/@/components/Table';
import {
  FormSchema
} from '/@/components/Table';
import {
  rules
} from '/@/utils/helper/validator';
import {
  render
} from '/@/utils/common/renderUtils';
import {
  JVxeTypes,
  JVxeColumn
} from '/@/components/jeecg/JVxeTable/types'
//列表数据
export const columns: BasicColumn[] = [{
  title: '编码',
  align: "center",
  sorter: true,
  width: '100px',
  dataIndex: 'code'
},
{
  title: '名称',
  align: "center",
  sorter: true,
  width: '260px',
  dataIndex: 'name'
},
{
  title: '规格',
  align: "center",
  width: '140px',
  dataIndex: 'spec'
},
{
  title: '车间编码',
  align: "center",
  sorter: true,
  width: '120px',
  dataIndex: 'workshopCode'
},
{
  title: '排序',
  align: "center",
  sorter: true,
  width: '80px',
  dataIndex: 'departOrder'
},
{
  title: '车间',
  align: "center",
  width: '100px',
  dataIndex: 'workshopName'
},
{
  title: '设备分组',
  align: "center",
  width: '100px',
  dataIndex: 'cardNumber'
},
{
  title: '维保冲次',
  align: "center",
  width: '100px',
  dataIndex: 'maintenanceCharge'
},
{
  title: '加工工艺',
  align: "center",
  width: '100px',
  dataIndex: 'processManagementName'
},
{
  title: '数量',
  align: "center",
  width: '80px',
  dataIndex: 'quantity'
},
{
  title: '单位',
  align: "center",
  width: '100px',
  dataIndex: 'unitName'
},
{
  title: '启用日期',
  align: "center",
  width: '100px',
  dataIndex: 'enableDate',
  customRender: ({
    text
  }) => {
    return !text ? "" : (text.length > 10 ? text.substr(0, 10) : text)
  },
},
{
  title: '生产厂家',
  align: "center",
  width: '120px',
  dataIndex: 'manufacturerName'
},
{
  title: '存放地点',
  align: "center",
  width: '120px',
  dataIndex: 'useDepartmentName'
},
{
  title: '当前冲次',
  align: "center",
  width: '100px',
  dataIndex: 'currentCharge'
},
{
  title: '冲次总计',
  align: "center",
  width: '100px',
  dataIndex: 'chargeTotal'
},
{
  title: '状态',
  align: "center",
  width: '80px',
  dataIndex: 'status',
  customRender: ({
    text
  }) => {
    return text == 0 ? "上线" : text == 1 ? '空闲' : text == 2 ? "维保" : text == 2 ? '报废' : ''
  },
},
{
  title: '是否专用',
  align: "center",
  width: '100px',
  dataIndex: 'specialPurpose',
  customRender: ({
    text
  }) => {
    return text == 0 ? "否" : text == 1 ? '是' : ''
  },
},
{
  title: '是否在线',
  align: "center",
  width: '100px',
  dataIndex: 'online',
  customRender: ({text}) => text == 0 ? "否" : text == 1 ? '是' : ''
},
{
  title: '备注',
  align: "center",
  width: '80px',
  dataIndex: 'remark'
},
{
  title: '第三方编码',
  align: "center",
  width: '110px',
  dataIndex: 'thirdPartyCode',
  ifShow: false
},
];
//查询数据
export const searchFormSchema: FormSchema[] = [{
  label: "编码",
  field: "code",
  component: 'Input',
  colProps: {
    span: 6
  },
},
{
  label: "名称",
  field: "name",
  component: 'Input',
  colProps: {
    span: 6
  },
},
  // {
  //     label: "车间编码",
  //     field: "workshopCode",
  //     component: 'Input',
  //     colProps: {span: 6},
  // },
];
//表单数据
export const formSchema: FormSchema[] = [{
  label: '编码',
  field: 'code',
  component: 'Input',

  dynamicRules: ({ }) => [{ required: true, message: '请输入编码!' }]
},
{
  label: '设备',
  field: 'name',
  component: 'Input',
  dynamicRules: ({ }) => [{ required: true, message: '请输入设备!' }]
},
{
  label: '规格',
  field: 'spec',
  component: 'Input',
},
{
  label: '车间ID',
  field: 'workshopId',
  component: 'Input',
  show: false
},
{
  label: '车间编码',
  field: 'workshopCode',
  component: 'Input',
  slot: "workshopSlot",
  // dynamicRules: ({ }) => [{ required: true, message: '请选择车间编码!' }]
},
{
  label: '车间',
  field: 'workshopName',
  component: 'Input',
  dynamicDisabled: true,
  componentProps: {
    placeholder: '选择车间编码后带出',
  }
},
{
  label: '设备分组',
  field: 'cardNumber',
  component: 'Input',
},
{
  label: '维保冲次',
  field: 'maintenanceCharge',
  component: 'InputNumber',
},
{
  label: '加工工艺',
  field: 'processManagementName',
  component: 'Input',
  slot: "processManagement"
},
{
  label: '加工工艺ID',
  field: 'processManagementId',
  component: 'Input',
  show: false
},
{
  label: '加工工艺编码',
  field: 'processManagementCode',
  component: 'Input',
  show: false
},
{
  label: '数量',
  field: 'quantity',
  component: 'InputNumber',
},
{
  label: '单位ID',
  field: 'unitId',
  component: 'Input',
  show: false
},
{
  label: '单位',
  field: 'unitName',
  component: 'Input',
  slot: 'unitSlot'
},
{
  label: '启用日期',
  field: 'enableDate',
  component: 'DatePicker',
},
{
  label: '生产厂家ID',
  field: 'manufacturerId',
  component: 'Input',
  show: false
},
{
  label: '生产厂家',
  field: 'manufacturerId',
  component: 'JSelectDept',
  componentProps: ({ }) => {
    return {
      multiple: false,
      showButton: false,
      checkable: false
    }
  },
},
{
  label: '存放地点ID',
  field: 'useDepartmentId',
  component: 'Input',
  show: false
},
{
  label: '存放地点',
  field: 'useDepartmentName',
  component: 'Input',
  slot: "useDepartment",
  componentProps: ({ }) => {
    return {
      multiple: false,
      showButton: false,
      checkable: false
    }
  },
},
{
  label: '排序',
  field: 'departOrder',
  component: 'InputNumber',

},
{
  label: '当前冲次',
  field: 'currentCharge',
  component: 'InputNumber',
},
{
  label: '冲次总计',
  field: 'chargeTotal',
  component: 'InputNumber',
},
{
  label: '状态',
  field: 'status',
  component: 'Select',
  componentProps: {
    options: [{
      label: '上线',
      value: 0
    }, {
      label: '空闲',
      value: 1
    }, {
      label: '维保',
      value: 2
    }, {
      label: '报废',
      value: 3
    }],
    stringToNumber: true,
  },
  defaultValue: 1
},
{
  label: '是否专用',
  field: 'specialPurpose',
  component: 'Select',
  componentProps: {
    options: [{
      label: '否',
      value: 0
    }, {
      label: '是',
      value: 1
    }],
    stringToNumber: true
  },
  defaultValue: 1
},
{
  label: '是否在线',
  field: 'online',
  component: 'Select',
  componentProps: {
    options: [{
      label: '否',
      value: 0
    }, {
      label: '是',
      value: 1
    }],
    stringToNumber: true,
  }
},
{
  label: '备注',
  field: 'remark',
  component: 'Input',
},
{
  label: '第三方编码',
  field: 'thirdPartyCode',
  component: 'Input',
  ifShow: false
},
// TODO 主键隐藏字段，目前写死为ID
{
  label: '',
  field: 'id',
  component: 'Input',
  show: false
},
];
//子表单数据
//子表表格配置
export const basDeviceItemColumns: JVxeColumn[] = [{
  title: '设备主档ID',
  key: 'deviceId',
  type: JVxeTypes.hidden,
  width: "120px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '使用日期',
  key: 'useDate',
  type: JVxeTypes.date,
  width: "100px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '零件图号',
  key: 'partDrawingNo',
  type: JVxeTypes.input,
  width: "100px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '零件',
  key: 'partName',
  type: JVxeTypes.input,
  width: "80px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '存放地点ID',
  key: 'useDepartmentId',
  type: JVxeTypes.hidden,
  width: "120px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '存放地点',
  key: 'useDepartmentId',
  type: JVxeTypes.departSelect,
  width: "100px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '上机时间',
  key: 'operateTime',
  type: JVxeTypes.date,
  width: "100px",
  placeholder: '请输入${title}',
  defaultValue: '',
  validateRules: [
    {
      handler({ cellValue, row }, callback) {
        let startTime = new Date(cellValue).getTime();
        let endTime = new Date(row.deplaneTime).getTime();
        if (startTime > endTime) {
          callback(false, '${title}不能大于下机时间')
        } else {
          callback(true);
        }
      }
    }
  ],
},
{
  title: '上机人员ID',
  key: 'operatePersonId',
  type: JVxeTypes.hidden,
  width: "120px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '上机人员工号',
  key: 'operatePersonCode',
  type: JVxeTypes.hidden,
  width: "140px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '上机人员',
  key: 'operatePersonId',
  type: JVxeTypes.userSelect,
  width: "100px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '下机时间',
  key: 'deplaneTime',
  type: JVxeTypes.date,
  width: "100px",
  placeholder: '请输入${title}',
  defaultValue: '',
  validateRules: [
    {
      handler({ cellValue, row }, callback) {
        let startTime = new Date(cellValue).getTime();
        let endTime = new Date(row.operateTime).getTime();
        if (startTime < endTime) {
          callback(false, '${title}不能小于上机时间')
        } else {
          callback(true);
        }
      }
    }
  ],
},
{
  title: '下机人员ID',
  key: 'deplanePersonId',
  type: JVxeTypes.hidden,
  width: "120px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '下机人员工号',
  key: 'deplanePersonCode',
  type: JVxeTypes.hidden,
  width: "120px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '下机人员',
  key: 'deplanePersonName',
  type: JVxeTypes.userSelect,
  width: "120px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '工作时长',
  key: 'workHours',
  type: JVxeTypes.inputNumber,
  width: "120px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '备注',
  key: 'remark',
  type: JVxeTypes.input,
  width: "80px",
  placeholder: '请输入${title}',
  defaultValue: '',
},
{
  title: '第三方编码',
  key: 'thirdPartyCode',
  type: JVxeTypes.hidden,
  width: "110px",
  placeholder: '请输入${title}',
  defaultValue: ''
},
]


/**
 * 流程表单调用这个方法获取formSchema
 * @param param
 */
export function getBpmFormSchema(_formData): FormSchema[] {
  // 默认和原始表单保持一致 如果流程中配置了权限数据，这里需要单独处理formSchema
  return formSchema;
}
